
#This script produces Figure 3 in the main text

setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
   
library(foreign)
library(rmeta)
library(plotrix)





##########################
#Regression Plots for Micro Data
##########################
pdf("figure3_RplotALT.pdf", width=7, height=7)
par(mfrow=c(2,3),oma=c(0,0,2,0))
par(mar=c(3, 3, 2, 2))
#par(mar=c(2, 4, 1, 1))


a7nd<-read.dta("Arep7nd.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

a7nnd<-read.dta("Arep7nnd.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority", ylab = "Support for Forcible Return", pch = 20, cex.axis = .65, main = "A. Forcible Return, Rep. Priority, \nand Republican Identifiers", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")
abline(h=.5, lty=2)
 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())



a7nd<-read.dta("Adem7nd.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

a7nnd<-read.dta("Adem7nnd.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority", ylab = "Support for Forcible Return", pch = 20, cex.axis = .65, main = "B. Forcible Return, Rep. Priority, \nand Democratic Identifiers", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")
abline(h=.5, lty=2)
 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())



a7nd<-read.dta("Aall7nd.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

a7nnd<-read.dta("Aall7nnd.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority", ylab = "Support for Forcible Return", pch = 20, cex.axis = .65, main = "C. Forcible Return, GOP Priority, \nand All Respondents", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")
abline(h=.5, lty=2)
 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())

###########DEM PRIORITY PLOTS#############


a7nd<-read.dta("Arep7D.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Democrat Priority", ylab = "Support for Forcible Return", pch = 20, cex.axis = .65, main = "D. Forcible Return, Dem. Priority, \nand Republican Identifiers", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")
abline(h=.5, lty=2)

 rm(list=ls())



a7nd<-read.dta("Adem7D.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Democrat Priority", ylab = "Support for Forcible Return", pch = 20, cex.axis = .65, main = "E. Forcible Return, Dem. Priority, \nand Democratic Identifiers", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")
abline(h=.5, lty=2)
 

rm(list=ls())



a7nd<-read.dta("Aall7D.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Democrat Priority", ylab = "Support for Forcible Return", pch = 20, cex.axis = .65, main = "F. Forcible Return, Dem. Priority, \nand All Respondents", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")
abline(h=.5, lty=2)
 
title("Partisan Cues and Restrictionist Immigration Opinion", outer=TRUE)

rm(list=ls())
dev.off()
